import {createSlice} from "@reduxjs/toolkit"

const countReducer = createSlice({
    // reducer的名字必须是唯一的
    name:"count",
    //仓库数据初始化
    initialState:{
        count:0,
        list:[]
    },
    //执行初始化数据更新修改
    reducers:{
        //修改count属性
        //state就是initialState里面的数据
        //action就是通知对象，通知接下来如何操作数据
        //action标准格式：{type:"",payload：}
        setCount(state,action){
            console.log(action);
            state.count += action.payload
        },
        reduceCount(state,action){
            console.log(action);
            state.count -= 5
        },
        setList(state,action){
            state.list = [1,2,3,4]
        }
    }
})

//页面上要调用setCount，将这个作为通知对象
export const {setCount,setList,reduceCount} = countReducer.actions

export default countReducer.reducer